package lianxi;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import com.DBUtil;

public class _02_ {

	public static void main(String[] args) throws ClassNotFoundException, SQLException {
//		Connection connection = DBUtil.getConnection();
//		String sql = "INSERT INTO t_order (id, addr, NAME, phone)\r\n" + "VALUES\r\n" + "	(\r\n" + "		100001,\r\n"
//				+ "		'河北石家庄裕华区师大科技园B座1808',\r\n" + "		'小张',\r\n" + "		18931371111\r\n" + "	);\r\n" + "";
//		PreparedStatement preparedStatement = connection.prepareStatement(sql);
//		int count = preparedStatement.executeUpdate(sql);
//		System.out.println(count);
//		DBUtil.close(preparedStatement);
//		DBUtil.close(connection);

//		Connection connection = DBUtil.getConnection();
//		String sql = "INSERT INTO t_goods (NAME, price, order_id)\r\n" + 
//				"VALUES	('小米电视',3999,(SELECT id FROM t_order WHERE id = 100001 ) );";
//		PreparedStatement preparedStatement = connection.prepareStatement(sql);
//		int count = preparedStatement.executeUpdate(sql);
//		System.out.println(count);
//		DBUtil.close(preparedStatement);
//		DBUtil.close(connection);

		Connection connection = DBUtil.getConnection();
		String sql = "INSERT INTO t_goods (NAME, price, order_id)\r\n"
				+ "VALUES ( '格力空调', 5999, ( SELECT id FROM t_order WHERE id = 100001 ));";
		PreparedStatement preparedStatement = connection.prepareStatement(sql);
		int count = preparedStatement.executeUpdate(sql);
		System.out.println(count);
		DBUtil.close(preparedStatement);
		DBUtil.close(connection);
	}

}
